/**
 * 
 */
package com.wubo.common.web;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Controller;

import com.wubo.common.io.HttpDirectedProxy;

/**
 * 为前台脚本提供跨域访问
 * @author WuBo
 * @CreateDate 2012-2-17
 */
@Controller
public class ScriptCrossDomainAction extends BaseAction {
	private String url;

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}
	
	@SuppressWarnings("unchecked")
	public void crossDomain() throws Exception {
		Map<String, String> paramMap = new HashMap<String, String>();
		
		Enumeration enume = getHttpServletRequest().getParameterNames();
		while(enume.hasMoreElements()){
			String key = (String) enume.nextElement();
			String value = getHttpServletRequest().getParameter(key);
			paramMap.put(key, value);
		}
		String method = getHttpServletRequest().getMethod();
		HttpDirectedProxy.proxy(url, paramMap, method, getHttpServletResponse().getOutputStream());
	}
}
